import  {myaddressQuery} from  "@/model/myAddress"
export  default  {
    namespaced:true,
    state:{
        list:[],//地址列表,
        chooseId:0,//选择的是哪一个
    },
    mutations:{
        initList(state,payload){//是一个集合
            state.list  = payload
        },
        setChooseId(state,payload){
            state.chooseId = payload;
        }
    },
    actions:{
      async  initList({commit},params){
            let  res  = await  myaddressQuery(params);
            commit("initList",res.data);
        }
    },
    getters:{//等价于computed
        defaultChooseId(state){
            let  id  = 1;
            if(state.list.length){
                let  defautlInfo  = state.list.filter(item=>item.isDefault)[0];
                if(defautlInfo){
                    id = defautlInfo.id;
                }else{
                    id    = state.list[0]["id"];
                }
                if(state.chooseId){
                    id = state.chooseId;
                }
            }
            return  id;    
        }

    }
}